﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace _17_Task_异常捕获
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Task task = Task.Run(DoWork);

            try
            {
                task.Wait();//阻塞当前线程直到task完成
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());
            }

            Console.Read();
        }

        public static void DoWork()
        {
            Console.WriteLine("开始工作");
            Thread.Sleep(200);
            throw new InvalidCastException("发生无效操作");//自定义异常错误
        }

    }
}
